﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace UserAuthen.Migrations
{
    /// <inheritdoc />
    public partial class exp7 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Exam",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "TEXT", nullable: false),
                    ExamId = table.Column<Guid>(type: "TEXT", nullable: false),
                    ExamName = table.Column<string>(type: "TEXT", nullable: false),
                    RegistrationStartTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    RegistrationEndTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    ScheduleStartTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    ScheduleEndTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    ExamStartTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    ExamEndTime = table.Column<DateTime>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Exam", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "ExamRoom",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "TEXT", nullable: false),
                    ExamRoomId = table.Column<Guid>(type: "TEXT", nullable: false),
                    ExamRoomName = table.Column<string>(type: "TEXT", nullable: false),
                    Campus = table.Column<int>(type: "INTEGER", nullable: false),
                    BuildingName = table.Column<string>(type: "TEXT", nullable: false),
                    RoomNumber = table.Column<string>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ExamRoom", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "Registration",
                columns: table => new
                {
                    ID = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    DocumentType = table.Column<int>(type: "INTEGER", nullable: false),
                    DocumentNumber = table.Column<string>(type: "TEXT", nullable: false),
                    Workplace = table.Column<int>(type: "INTEGER", nullable: false),
                    PhoneNumber = table.Column<string>(type: "TEXT", nullable: false),
                    Gender = table.Column<int>(type: "INTEGER", nullable: false),
                    Bank = table.Column<string>(type: "TEXT", nullable: false),
                    BankAccountNumber = table.Column<string>(type: "TEXT", nullable: false),
                    ExamCampus = table.Column<int>(type: "INTEGER", nullable: false),
                    PickUpLocation = table.Column<int>(type: "INTEGER", nullable: false),
                    ParticipatedLastYear = table.Column<bool>(type: "INTEGER", nullable: false),
                    ExamID = table.Column<int>(type: "INTEGER", nullable: false),
                    ExamID1 = table.Column<Guid>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Registration", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Registration_Exam_ExamID1",
                        column: x => x.ExamID1,
                        principalTable: "Exam",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ExamRoomAssociation",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "TEXT", nullable: false),
                    AssociationId = table.Column<Guid>(type: "TEXT", nullable: false),
                    ExamId = table.Column<Guid>(type: "TEXT", nullable: false),
                    ExamRoomId = table.Column<Guid>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ExamRoomAssociation", x => x.ID);
                    table.ForeignKey(
                        name: "FK_ExamRoomAssociation_ExamRoom_ExamRoomId",
                        column: x => x.ExamRoomId,
                        principalTable: "ExamRoom",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ExamRoomAssociation_Exam_ExamId",
                        column: x => x.ExamId,
                        principalTable: "Exam",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ExamRoomAllocation",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "TEXT", nullable: false),
                    AllocationId = table.Column<Guid>(type: "TEXT", nullable: false),
                    ExamId = table.Column<Guid>(type: "TEXT", nullable: false),
                    ExamRoomId = table.Column<Guid>(type: "TEXT", nullable: false),
                    Supervisor1ID = table.Column<int>(type: "INTEGER", nullable: false),
                    Supervisor2ID = table.Column<int>(type: "INTEGER", nullable: false),
                    AllocationStatus = table.Column<string>(type: "TEXT", nullable: false),
                    AllocationRules = table.Column<string>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ExamRoomAllocation", x => x.ID);
                    table.ForeignKey(
                        name: "FK_ExamRoomAllocation_ExamRoom_ExamRoomId",
                        column: x => x.ExamRoomId,
                        principalTable: "ExamRoom",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ExamRoomAllocation_Exam_ExamId",
                        column: x => x.ExamId,
                        principalTable: "Exam",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ExamRoomAllocation_Registration_Supervisor1ID",
                        column: x => x.Supervisor1ID,
                        principalTable: "Registration",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ExamRoomAllocation_Registration_Supervisor2ID",
                        column: x => x.Supervisor2ID,
                        principalTable: "Registration",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ExamRoomAllocation_ExamId",
                table: "ExamRoomAllocation",
                column: "ExamId");

            migrationBuilder.CreateIndex(
                name: "IX_ExamRoomAllocation_ExamRoomId",
                table: "ExamRoomAllocation",
                column: "ExamRoomId");

            migrationBuilder.CreateIndex(
                name: "IX_ExamRoomAllocation_Supervisor1ID",
                table: "ExamRoomAllocation",
                column: "Supervisor1ID");

            migrationBuilder.CreateIndex(
                name: "IX_ExamRoomAllocation_Supervisor2ID",
                table: "ExamRoomAllocation",
                column: "Supervisor2ID");

            migrationBuilder.CreateIndex(
                name: "IX_ExamRoomAssociation_ExamId",
                table: "ExamRoomAssociation",
                column: "ExamId");

            migrationBuilder.CreateIndex(
                name: "IX_ExamRoomAssociation_ExamRoomId",
                table: "ExamRoomAssociation",
                column: "ExamRoomId");

            migrationBuilder.CreateIndex(
                name: "IX_Registration_ExamID1",
                table: "Registration",
                column: "ExamID1");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ExamRoomAllocation");

            migrationBuilder.DropTable(
                name: "ExamRoomAssociation");

            migrationBuilder.DropTable(
                name: "Registration");

            migrationBuilder.DropTable(
                name: "ExamRoom");

            migrationBuilder.DropTable(
                name: "Exam");
        }
    }
}
